package cn.stylefeng.guns.sys.modular.system.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.sys.core.util.JsonResult;
import cn.stylefeng.guns.sys.modular.system.service.BtyDdpxService;
import cn.stylefeng.guns.sys.modular.system.warpper.NoticeWrapper;
import cn.stylefeng.roses.core.base.controller.BaseController;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.Map;

@Controller
@RequestMapping("/btyDdpx")
public class BtyDdpxController extends BaseController {

    private String PREFIX = "/modular/system/btyDdpx/";
    @Resource
    private BtyDdpxService btyDdpxService;

    /**
     * 跳转到员工培训页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "btyDdpx.html";
    }

    /**
     * 获取培训列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list() {
        Page<Map<String, Object>> list = this.btyDdpxService.list("");
        Page<Map<String, Object>> wrap = new NoticeWrapper(list).wrap();
        return LayuiPageFactory.createPageInfo(wrap);
    }
    /**
     * 获取培训列表(不分页)
     */
    @RequestMapping(value = "/listAll")
    @ResponseBody
    public Object listAll() {
        return this.btyDdpxService.listAll();
    }

    /**
     * 导入excel
     */
    @RequestMapping("/import")
    @ResponseBody
    public Object ddpx(@RequestParam("file") MultipartFile file) {
        String fileName = file.getOriginalFilename();
        JsonResult jsonResult = new JsonResult();
        int result;
        try {
            result = this.btyDdpxService.batchImport(fileName, file);
        } catch (Exception e) {
            e.printStackTrace();
            jsonResult.setState(0);
            jsonResult.setErrmsg(e.getMessage());
            return jsonResult;
        }
        return result;
    }

}